//
//  AccountCenterHeaderView.m
//  JiaoX
//
//  Created by jiaoxiu－005 on 15/1/16.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "AccountCenterHeaderView.h"
#define margintop 10
#define marginleft 10
#define titleLabelColor JXColor(77, 77, 77)
#define ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE [DimensUtils getScaleX:15]
#define ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_DETAIL [DimensUtils getScaleX:13]
#define ACCOUNT_CENTER_HEADER_VIEW_ADDRESS [DimensUtils getScaleX:10]
@interface AccountCenterHeaderView()
{
    UIImageView *_cargoTitleIconView;
    UILabel *_cargoTitleLabel;
    UIView *_cargolineView;
    UILabel *_cargoAddressNameLabel;
    UILabel *_cargoAddressPhoneLabel;
    UILabel *_cargoAddressDetailLabel;
    UIImageView *_orderTitleIconView;
    UILabel *_orderTitleLabel;
    UIView *_orderlineView;
}
@end

@implementation AccountCenterHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //1.收货信息UIimageView
        UIImageView *cargoTitleIconView =[[UIImageView alloc]init];
        UIImage *cargoTileIcon = [UIImage imageNamed:@"account_center_cargo_address"];
        [cargoTitleIconView setImage:cargoTileIcon];
        [cargoTitleIconView setFrame:CGRectMake(marginleft, margintop, cargoTileIcon.size.width, cargoTileIcon.size.height)];
        _cargoTitleIconView = cargoTitleIconView;
        [self addSubview:cargoTitleIconView];
        
        //2.收货信息UIlabel
        NSString *cargoTitleText = @"收货信息";
        UILabel *cargoTitleLabel = [[UILabel alloc]init];
        [cargoTitleLabel setText:cargoTitleText];
        [cargoTitleLabel setTextColor:titleLabelColor];
        [cargoTitleLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
        CGSize cargoTileSize = [cargoTitleText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
        [cargoTitleLabel setFrame:CGRectMake(CGRectGetMaxX(_cargoTitleIconView.frame)+5, margintop, cargoTileSize.width, cargoTileSize.height)];
        _cargoTitleLabel = cargoTitleLabel;
        [self addSubview:cargoTitleLabel];
        
        //3.分割线UIView
        UIView * cargolineView = [[UIView alloc]initWithFrame:CGRectMake(marginleft, CGRectGetMaxY(_cargoTitleIconView.frame)+margintop, JXScreenW-marginleft, 0.5)];
        [cargolineView setBackgroundColor:JXColor(204, 204, 204)];
        _cargolineView = cargolineView;
        [self addSubview:cargolineView];
        
        //4.姓名UIlabel
        NSString *cargoAddressNameText = @"姓名";
        UILabel *cargoAddressNameLabel = [[UILabel alloc]init];
        [cargoAddressNameLabel setText:cargoAddressNameText];
        [cargoAddressNameLabel setTextColor:JXColor(0, 0, 0)];
        [cargoAddressNameLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
        CGSize cargoAddressNameTextSize = [cargoAddressNameText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
        [cargoAddressNameLabel setFrame:CGRectMake(marginleft, CGRectGetMaxY(_cargolineView.frame)+margintop, cargoAddressNameTextSize.width, cargoAddressNameTextSize.height)];
        _cargoAddressNameLabel = cargoAddressNameLabel;
        [self addSubview:cargoAddressNameLabel];
        
        //5.电话UIlabel
        NSString *cargoAddressPhoneText = @"电话";
        UILabel *cargoAddressPhoneLabel = [[UILabel alloc]init];
        [cargoAddressPhoneLabel setText:cargoAddressPhoneText];
        [cargoAddressPhoneLabel setTextColor:titleLabelColor];
        [cargoAddressPhoneLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
        CGSize cargoAddressPhoneTextSize = [cargoAddressPhoneText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
        [cargoAddressPhoneLabel setFrame:CGRectMake(marginleft, CGRectGetMaxY(_cargoAddressNameLabel.frame)+margintop, cargoAddressPhoneTextSize.width, cargoAddressPhoneTextSize.height)];
        _cargoAddressPhoneLabel = cargoAddressPhoneLabel;
        [self addSubview:cargoAddressPhoneLabel];
        
        //5.1 箭头
        UIImageView *arrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"self_item_arrow"]];
        [arrow setSize:arrow.image.size];
        arrow.x = JXScreenW-JXPublicInset-arrow.width;
        arrow.centerY = cargoAddressPhoneLabel.centerY;
        [self addSubview:arrow];

        //6.地址UIlabel
        NSString *cargoAddressDetailText = @"详细地址";
        UILabel *cargoAddressDetailLabel = [[UILabel alloc]init];
        [cargoAddressDetailLabel setText:cargoAddressDetailText];
        [cargoAddressDetailLabel setTextColor:JXColor(128, 128, 128)];
        [cargoAddressDetailLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_DETAIL]];
        CGSize cargoAddressDetailSize = [cargoAddressDetailText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_DETAIL]];
        [cargoAddressDetailLabel setFrame:CGRectMake(marginleft, CGRectGetMaxY(_cargoAddressPhoneLabel.frame)+margintop, cargoAddressDetailSize.width, cargoAddressDetailSize.height)];
        _cargoAddressDetailLabel = cargoAddressDetailLabel;
        [self addSubview:cargoAddressDetailLabel];
        
        //7.订单信息UIimageView
        UIImageView *orderTitleIconView =[[UIImageView alloc]init];
        UIImage *orderTileIcon = [UIImage imageNamed:@"account_center_header_order_icon"];
        [orderTitleIconView setImage:orderTileIcon];
        [orderTitleIconView setFrame:CGRectMake(marginleft, CGRectGetMaxY(_cargoAddressDetailLabel.frame)+32, orderTileIcon.size.width, orderTileIcon.size.height)];
        _orderTitleIconView = orderTitleIconView;
        [self addSubview:orderTitleIconView];
        
        
        //8.订单信息UIlabel
        NSString *orderTitleText = @"订单信息";
        UILabel *orderTitleLabel = [[UILabel alloc]init];
        [orderTitleLabel setText:orderTitleText];
        [orderTitleLabel setTextColor:titleLabelColor];
        [orderTitleLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
        CGSize orderTitleTextSize = [orderTitleText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
        [orderTitleLabel setFrame:CGRectMake(CGRectGetMaxX(_orderTitleIconView.frame)+5, CGRectGetMaxY(_cargoAddressDetailLabel.frame)+30, orderTitleTextSize.width, orderTitleTextSize.height)];
        _orderTitleLabel = orderTitleLabel;
        [self addSubview:orderTitleLabel];
        
        //9.分割线UIView
        UIView * orderlineView = [[UIView alloc]initWithFrame:CGRectMake(marginleft, CGRectGetMaxY(_orderTitleIconView.frame) + margintop, JXScreenW - marginleft, 0.5)];
        [orderlineView setBackgroundColor:JXColor(204, 204, 204)];
        _orderlineView = orderlineView;
        [self addSubview:orderlineView];
        
        [self setBounds:CGRectMake(0, 0, JXScreenW, CGRectGetMaxY(_orderlineView.frame))];
        
        UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(checkAddress)];
        
        [self addGestureRecognizer:tapGesture];
    }
    return self;
}
-(void)setAddressName:(NSString *)addressName{
    CGSize addressNameSize = [addressName sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
    [_cargoAddressNameLabel setSize:addressNameSize];
    [_cargoAddressNameLabel setText:addressName];
}
-(void)setAddressPhone:(NSString *)addressPhone{
    CGSize addressPhoneSize = [addressPhone sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_TITLE]];
    [_cargoAddressPhoneLabel setSize:addressPhoneSize];
    [_cargoAddressPhoneLabel setText:addressPhone];
}
-(void)setAddressDetail:(NSString *)addressDetail{
    CGSize addressDetailSize = [addressDetail sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_HEADER_VIEW_ADDRESS_DETAIL]];
    [_cargoAddressDetailLabel setSize:addressDetailSize];
    [_cargoAddressDetailLabel setText:addressDetail];
}

-(void)checkAddress{
    if ([self.delegate respondsToSelector:@selector(checkAddress)]) {
        [_delegate checkAddress];
    }
}
@end
